package com.gdk.ksoft.assembly.utils.system;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by hel on 2014-12-02.
 * 网络链接工具类
 */
public class NetworkUtils {

    /**
     * 网络是否可用
     * @param context
     * @return
     */
    public static boolean isNetAvailable(Context context){
        ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        if(info == null) return false;
        return info.isAvailable();
    }

    /**
     * WIFI链接状态是否可用
     * @param context
     * @return
     */
    public static boolean isWifiAvailable(Context context){
        ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        if(info == null) return false;
        if(info.getTypeName().equals("WIFI") && info.isAvailable()) return true;
        return false;
    }


}
